*************************************************************
*** Figures 4/E.7: Event Study: Physician Movers

	import delimited using "${mypath}/intermediate_csv/geotwfe01-eventstudy_ALL_physicians.csv", clear varnames(1)

	levelsof sample 
	foreach ptype in `r(levels)'{
		preserve 
			keep if sample == "`ptype'"
			# d;
				twoway (connect estimate relyear, lcolor("8 48 107") mcolor("8 48 107") lpattern(solid)) 
				(rcap min95 max95 relyear, lcolor("8 48 107") lpatter(dash)), 
				ytitle("Coefficient on Difference in Area Incomes ({&beta}{sub:{&tau}}) ", size(medlarge)) 
				xtitle("Year Relative to Move ({&tau})", size(medlarge)) xlabel(-6(1)6, labsize(medlarge) nogrid) 
				legend(off) 
				ylab(-0.5(0.5)1,labsize(medlarge))
				graphregion(color(white)) 
				yline(0, lcolor(black) lpattern(dash)) 
				xline(0, lwidth(5.5) lc(gs12*.4) lpattern(solid))
				xsize(6);
			#d cr	
			graph export "${individ_figs}/geotwfe01-eventstudy_`ptype'.eps", replace 	
		restore 
	}

*************************************************************
*** Figure 5: Place vs. Physician Contributions to Earnings 

	*****************************
	*** Panels A and B 

	cap program drop renaming
	program renaming 
		replace effect = "var_y" if effect == "logptotinc"
		replace effect = "cov_psi__alpha" if effect == "Place/Individ" | effect == "Firm/Individ"
		replace effect = "var_psi" if effect == "Place" | effect == "Firm"
		replace effect = "var_eps" if effect == "resid"
		replace effect = "var_alpha" if effect == "Individ"
		ren covar_ `1' 
		ren var_share sh_var_`1'
	end 
	
	// Import PyTwoway results 
	import delimited using "${mypath}/intermediate_csv/twfe01-earnings_decompositions_pytwoway.csv", asdoub clear	
	keep sample effect __* sh*

	tempfile pytwoway
	save `pytwoway'
	
	// Import Card et al. (2013) earnings decomposition
	import delimited using "${mypath}/intermediate_csv/twfe01-earnings_decompositions.csv", asdoub clear
	keep if regexm(filename,"nocontrols") // == "geotwfe06-earnings_decomp_card_nocontrols"
		
	drop if spec == "Person-Year Level" | effect == "recomposed"
	renaming card
	merge 1:1 effect sample using `pytwoway', keep(3) nogen
	drop spec sd_ corr_
	keep if inlist(effect,"var_psi","cov_psi__alpha")		
		
	// Reshape
	ren _* var*
	loc i = 1
	levelsof sample
	foreach sample in `r(levels)' {
	preserve
		keep if sample == "`sample'"
		reshape long sh_var_ var_, i(effect) j(estimator) string  
		tempfile temp`i'
		save `temp`i''
		loc ++i
	restore		
	}

	clear
	use `temp1', clear
	append using `temp2'
	append using `temp3'
	
	drop if estimator == "card"
		
	// General layout
	grstyle set plain, horizontal grid dotted
	g d_eff = effect == "cov_psi__alpha"
	g d_est = 1 if estimator == "fe"
	replace d_est = 2 if estimator == "ho"
	replace d_est = 3 if estimator == "he"
	
	replace sh_var_ = 2 * sh_var_ if effect == "cov_psi__alpha"
	replace var_ = 2 * var_ if effect == "cov_psi__alpha"
	
	// Physicians
	#d;
	graph bar var_ if sample == "physicians", 
		over(d_est, gap(*1.7)) 
		over(d_eff, 
		relabel(1 "Location Effect: Var({&psi}{sub:c})" 
		2 "Sorting Effect: 2 x Cov({&alpha}{sub:i},{&psi}{sub:c})") 
		label(labsize(medlarge)) gap(*1.5)) 
	asyvars bar(1, color("8 48 107"%80)) bar( 2, color("33 113 181"%80)) bar( 3, color(eltblue%80)) 
	ytitle("") 
	ymtick(##2)
	ylabel(,labsize(medlarge) grid) 
	bargap(10)
	legend( label(1 "Two-Way Fixed Effects")
	label(2 "Homoskedastic Correction") 
	label(3 "Heteroskedastic Correction") rows(1) pos(6) size(medsmall)) 
	yline(0, lc(gs12) noextend)
	title("(Co-)" "Variance", size(medium) placement(9) span justification(left) col(black))
	;
	#d cr
	graph export "${individ_figs}/geotwfe02-earnings_variance_decomp_physicians.eps", replace
	
	// Lawyers
	#d;
	graph bar var_ if sample == "lawyers", 
	over(d_est, gap(*1.7)) 
	over(d_eff, 
		relabel(1 "Location Effect: Var({&psi}{sub:c})" 
		2 "Sorting Effect: 2 x Cov({&alpha}{sub:i},{&psi}{sub:c})") 
		label(labsize(medlarge)) gap(*1.5)) 
	asyvars bar(1, color("8 48 107"%80)) bar( 2, color("33 113 181"%80)) bar( 3, color(eltblue%80)) 
	ytitle("") 
	ymtick(##2)
	ylabel(,labsize(medlarge) grid) 
	bargap(10)
	legend( label(1 "Two-Way Fixed Effects")
	label(2 "Homoskedastic Correction") 
	label(3 "Heteroskedastic Correction") rows(1) pos(6) size(medsmall)) 
	yline(0, lc(gs12) noextend)
	title("(Co-)" "Variance", size(medlarge) placement(9) span justification(left) col(black))
	;
	#d cr
	graph export "${individ_figs}/geotwfe02-earnings_variance_decomp_lawyers.eps", replace

	*****************************
	*** Panels C and D 

	import delimited using "${mypath}/intermediate_csv/geotwfe0405-indivfe_vs_czfe_manualczfe.csv", clear delim(tab) varnames(1)
	
	* Person level (main TWFE specification)
	preserve 
	keep if specification == "__hdfePLACE__"
	loc ytitle "CZ Fixed Effects"
	
	local beta = slope[1]
	local cons = cons[1]
	qui su idfe 
	
	sort bin
	#d ;	
	tw  (scatter czfe idfe, mcolor("8 48 107"))
		(function y = `cons'+`beta'*x, range(`r(min)' `r(max)') lcolor(eltblue)),
		legend(off)
		xtitle("Individual Fixed Effects", size(medlarge))
		xlabel(,nogrid labsize(medlarge)) 
		ylabel(,labsize(medlarge) nogrid)
		ytitle("") 
		ymtick(##2)
		title(`ytitle', size(medlarge) placement(9) span justification(left) col(black) )
		;
	#d cr			
	graph export "${individ_figs}/geotwfe11-Corr_IDFEs_hdfePLACE.eps", replace	
	
	restore

	* Place level (main TWFE specification)
	preserve 
	keep if specification == "__hdfePLACE__ ID FE averaged"
	loc ytitle "CZ Fixed Effects"
	
	local beta = slope[1]
	local cons = cons[1]
	qui su idfe 
	
	sort bin
	#d ;	
	tw  (scatter czfe idfe, mcolor("8 48 107")) 
		(function y = `cons'+`beta'*x, range(`r(min)' `r(max)') lcolor(eltblue)),
		legend(off)
		xtitle("Average Individual Fixed Effects Within a CZ", size(medlarge))
		xlabel(,nogrid labsize(medlarge)) 
		ylabel(,labsize(medlarge) nogrid)
		ytitle("") 
		ymtick(##2)
		title(`ytitle', size(medlarge) placement(9) span justification(left) col(black) ) 
		;
	#d cr	
	graph export "${individ_figs}/geotwfe11-Corr_MEANIDFEs_hdfePLACE.eps", replace	
	
	restore

*************************************************************
*** Correlates of Place Effects (Figure 6)

	* Load data
	import delimited using "${mypath}/intermediate_csv/geotwfe09-cz_correlations.csv", clear asdoub
	destring max95, replace force
	drop sort
	drop if (sample == "lawyers" & indepvar != "med_hhinc2016") | indepvar == "med_hhinc2016 (physicians>10)" 
	drop if inlist(indepvar,"GAF","age65le","cz_price_index_hi","mean_fe_id_lawyers","mean_fe_id_physicians") | inlist(indepvar,"pcprate","count_docs_2017","pop_over65","reimb_penroll_adj10","frac_middleclass")
	
	drop if sample == "lawyers"
	* Labels
	* Panel A: Population Density
	replace label = "01.Log Population" if label == "Log Population"
	replace label = "02.Population Density" if label == "Population Density"
	
	* Panel B: General Economic Characteristics
	replace label = "04.Diamond and Moretti (2021) Price Index" if label == "Laspeyres Price Index"
	replace label = "05.Median Household Income in 2016" if indepvar == "med_hhinc2016"
	replace label = "06.Rural Index, 2013" if label == "Urban->Rural Continuum Code 2013"
	replace label = "07.% College Graduates" if label == "% College Grads"
	replace label = "08.Job Growth Rate 1990-2010" if label == "Job Growth Rate 1990-2010"
	replace label = "09.Median House Value" if label == "Median House Value"
	
	* Panel C: Life Expectancy
	replace label = "11.Life Expectancy" if label == "Life Expectancy"
	replace label = "12.Finkelstein et al. (2021) Mortality Treatment Effect" if label == "FGW Mortality Trt Effect"
	
	* Panel D: Healthcare System
	replace label = "15.Total # of Physicans (2005-2017)" if label == "Total # of Physicans (All years)"
	replace label = "16.# of PCPs per 100,000" if label == "# of PCPs per 100,000"
	replace label = "17.# of Non-PCPs per 100,000" if label == "# of Non-PCPs per 100,000"
	replace label = "18.# of Medicaid Eligible per 100,000" if label == "# Medicaid Eligible per 100,000"
	replace label = "19.# of Medicare Eligible per 100,000" if label == "# Medicare Eligible per 100,000"
	replace label = "20.% Uninsured" if label == "% Uninsured"
	
	* Panel headers
	gsort label depvar -sample
	insobs 1, before(1)
	replace label = "00.Panel A" if label == ""

	insobs 1, before(6)
	replace label = "03.Panel B" if label == ""
	
	insobs 1, before(21)
	replace label = "11.Panel C" if label == ""
	
	insobs 1, before(26)
	replace label = "14.Panel D" if label == ""
	
	* Graph
	g sort = substr(label,1,2)
	destring sort, replace
	replace label = substr(label, 4, .)
	gsort sort depvar -sample
	g y = (-1* _n - sort )*2
	
	preserve
		collapse (mean) y , by(label sample sort)
		g labs = 1
		tempfile labels
		save `labels', replace
	restore
	
	append using `labels'
	replace label = "{bf: } " if depvar != "" 

	* Graph
	gen tempflag = depvar=="Demeaned CZ-FEs"
	levelsof y if tempflag, loc(aux1)
	drop tempflag
	foreach line in `aux1' {
		loc ylines "`ylines' `=`line'+2'"
	}	
	labmask y, val(label)
	levelsof y if !strpos(label,"Panel"), loc(coeflabs)
	
	#d ;
	tw (scatter y estimate if depvar == "Demeaned CZ-FEs", lcolor("8 48 107"*0.8) mcolor("8 48 107"*0.8) msymbol(o) msize(small)) 
	   (rcap min95 max95 y if depvar == "Demeaned CZ-FEs", lcolor("8 48 107"*0.8) lpatter(solid) horizontal lwidth(medthin))
	   (scatter y estimate if depvar == "Demeaned Log Earnings", lcolor(eltblue*0.8) mcolor(eltblue*0.8) msymbol(o) msize(small)) 
	   (rcap min95 max95 y if depvar == "Demeaned Log Earnings", lcolor(eltblue*0.8) lpatter(solid) horizontal lwidth(medthin)), 
		ytitle("") xtitle("")  
		legend(order(2 "CZ FE Regression Coefficient" 4 "CZ Log Income Regression Coefficient") 
		rows(2) pos(6) size(vsmall))
		text(-2  -.47 "{bf:Panel A: Population Density}", place(e) size(vsmall)) 
		text(-18 -.47 "{bf:Panel B: General Economic Characteristics}", place(e) size(vsmall)) 
		text(-59 -.47 "{bf:Panel C: Life Expectancy}", place(e) size(vsmall)) 
		text(-75 -.47 "{bf:Panel D: Healthcare System}", place(e) size(vsmall)) 
		ylabel(`coeflabs', labsize(vsmall) valuelabel nogrid noticks) 
		ysc(r(-0 -118))
		xlab(-0.1(0.05)0.2, labsize(vsmall))
		xsc(r(-0.1 0.1))
		graphregion(color(white) m(l+10 t-55 b-57))
		yline(`ylines', lcolor(gs10) lpattern(dot) lwidth(thin))
		xline(0, lwidth(0.1) lc(gs11) lpattern(dash))  
		plotregion(margin(0))
		ysize(28) xsize(26) aspectratio(2)
		;			
	#d cr
	graph export "${individ_figs}/geotwfe09-cz_correlations.eps", replace

******************************************************
*** Firm and Individual Fixed Effects (Figure E.8)	

	* Load data
	import delimited using "${mypath}/intermediate_csv/firmtwfe01-Individual_vs_firm_FE.csv", clear asdoub
		
	foreach resid in residyear residczyear {
		
		local beta = `resid'_slope[1]
		local cons = `resid'_cons[1]
			
		su `resid'_indivfe
			loc ymax = `r(max)'
		su `resid'_firmfe
		
		#d ;	
		tw (scatter `resid'_indivfe `resid'_firmfe, mcolor("8 48 107")) 
			(function y = `cons'+`beta'*x, range(`r(min)' `r(max)') lcolor(eltblue)),
			legend(off)
			xtitle("Firm Fixed Effects", size(medlarge))
			xlabel(-0.8(0.2)0.6,nogrid labsize(medlarge)) 
			ylabel(,labsize(medlarge) nogrid)
			ytitle("") 
			ymtick(##2)
			text(`ymax' 0.4 "{&beta} = `beta'", color(black) size(medium) justification(left)  placement(e) linegap(1))
			legend(off)
			title("Individual" "Fixed Effects", size(medlarge) placement(9) span justification(center) col(black) );
		#d cr		
		
	graph export "${individ_figs}/firmtwfe01-Individual_vs_firm_FE_`resid'.eps", replace
	
	}

***********************************************************
*** Table E.6: Decomposition of Variation in Earnings 

	* Earnings decomposition
	cap program drop renaming
	program renaming 
		replace effect = "var_y" if effect == "logptotinc"
		replace effect = "cov_psi__alpha" if effect == "Place/Individ" | effect == "Firm/Individ"
		replace effect = "var_psi" if effect == "Place" | effect == "Firm"
		replace effect = "var_eps" if effect == "resid"
		replace effect = "var_alpha" if effect == "Individ"
		ren covar_ `1' 
	end 
	
	* Import PyTwoway results 
	import delimited using "${mypath}/intermediate_csv/twfe01-earnings_decompositions_pytwoway.csv", asdoub clear
	keep sample effect __*

	tempfile pytwoway
	save `pytwoway'
	
	* Import Card et al. (2013) earnings decomposition 
	import delimited using "${mypath}/intermediate_csv/twfe01-earnings_decompositions.csv", asdoub clear
	drop if regexm(filename,"nocontrols") // == "geotwfe06-earnings_decomp_card_nocontrols"	
	drop if effect == "recomposed"
	
	renaming card
	g tempunitcard = card if spec == "CZ Level" | spec == "Firm Level"
	g perscard = card if spec == "Person-Year Level"
	bys sample effect: egen unitcard = max(tempunitcard)
	
	keep if spec == "Person-Year Level"
	keep sample effect unitcard perscard	
	replace sample = "physicians" if sample == "ALL"
	merge 1:1 effect sample using `pytwoway', keep(3) nogen
	keep if inlist(effect,"var_psi","cov_psi__alpha")		
		
	* Formatting 
	replace effect = "1.Location Effect: \$ \textnormal{Var}(\psi_c)\$" if effect == "var_psi"
	replace effect = "2.Sorting Effect: \$ 2 \times  \textnormal{Cov}(\alpha_i,\psi_c) \$" if effect == "cov_psi__alpha"

	bysort sample (effect): g sort = _n
	replace effect = substr(effect, 3, .)
		
	loc tableno " "
	loc tabspec "l"
	
	foreach s of numl 1(1)5 {
		loc tabspec "`tabspec'c"
		loc tableno "`tableno' & (`s')"
	}

	foreach v of varl *card *fe *ho *he  {	
		replace `v' = 2* `v' if regexm(effect,"Sorting")
		tostring `v', format("%04.3fc") replace force
	}

	* Table Earnings decomposition - Physicians (no controls)
	texdoc init "${tables}/geotwfe02-earnings_variance_decomposition.tex", replace
	
	tex \begin{table}[h!] 
	tex \caption{\bf Decomposition of Variation in Earnings \label{tab:twfe_variancedecomposition}} 
	tex \begin{center}
	tex \begin{tabular}{`tabspec'} 
	tex \midrule \midrule \addlinespace[1ex]	
	tex & \multicolumn{3}{c}{No Covariates} & \multicolumn{2}{c}{\shortstacking{Two-Way Fixed Effects \\ With Covariates}} \\
	tex \cmidrule(lr){2-4} \cmidrule(lr){5-6} 
	tex & \shortstacking{Two-Way \\ Fixed Effects} & \shortstacking{Homoskedastic \\ Bias Correction} & \shortstacking{Heteroskedastic \\ Bias Correction} & \shortstacking{Individual-\\ Level} & \shortstacking{CZ-Level / \\ Firm-Level} \\ 
	tex `tableno' \\ \addlinespace[0.5ex]	
	tex \midrule 
	
	gsort -sample sort
	
	forvalues k = 1(1)`=_N' {
		
		if `k' == 1 		tex \addlinespace[2ex]	\multicolumn{6}{l}{\textbf{Panel A: Physicans}} \\ \addlinespace[1ex]
		if `k' == 3 		tex \addlinespace[2ex]	\multicolumn{6}{l}{\textbf{Panel B: Lawyers}}   \\ \addlinespace[1ex]
		if `k' == 5 		tex \addlinespace[2ex]	\multicolumn{6}{l}{\textbf{Panel C: Firms}} \\ \addlinespace[1ex]
		
		tex `=effect[`k']' & `=__fe[`k']' & `=__ho[`k']'  & `=__he[`k']'  & `=perscard[`k']' & `=unitcard[`k']' \\ \addlinespace[1ex]			
	} 		

	tex \addlinespace[1ex] \hline \hline
	tex \end{tabular}
	tex \end{center}
	tex \end{table}
	
	texdoc close

********************************************************************
*** Table E.7: Decomposition of Variation in Earnings in Subsamples 

	* Prepare data
	import delimited using "${mypath}/intermediate_csv/twfe01-earnings_decompositions.csv", asdoub clear
	drop if inlist(sample, "firm-twfe (physicians)", "RESTRICSPEC") | filename == "geo_twfe/geotwfe06-earnings_decomp_card_nocontrols" & sample == "lawyers"
	drop file* sd_ corr_ var_share
	
	renaming card
	keep if effect == "cov_psi__alpha" | effect == "var_psi"
	replace spec = sample + "_PL" if spec == "Person-Year Level"
	replace spec = sample + "_CZL" if spec == "CZ Level"
	keep spec effect *card
	reshape wide card, i(effect) j(spec) string
	
	* Formatting 
	foreach var of varl card* {
		replace `var' = 2* `var' if effect == "cov_psi__alpha"
	}
	
	replace effect = "1.Location Effect: \$ \textnormal{Var}(\psi_c)\$" if effect == "var_psi"
	replace effect = "2.Sorting Effect: \$ 2 \times  \textnormal{Cov}(\alpha_i,\psi_c) \$" if effect == "cov_psi__alpha"

	sort effect
	g sort = _n
	replace effect = substr(effect, 3, .)
		
	loc tableno " "
	loc tabspec "l"
	loc collab " "
	
	foreach s of numl 1(1)7 {
		loc tabspec "`tabspec'c"
		loc tableno "`tableno' & (`s')"
	}

	foreach v of varl *card* {	
		tostring `v', format("%04.3fc") replace force
	}

	* Table Earnings decomposition - Physicians (no controls)
	texdoc init "${tables}/geotwfe02-earnings_variance_decomposition_subsamples.tex", replace
	
	tex \begin{table}[h!] 
	tex \caption{\bf Decomposition of Variation in Earnings in Subsamples \label{tab:twfe_variancedecomp_subsamples}} 
	tex \begin{center}
	tex \resizebox{1\textwidth}{!}{
	tex \begin{tabular}{`tabspec'} 
	tex \midrule \midrule \addlinespace[1ex]
	tex & \multicolumn{2}{c}{All Physicians} & & & \multicolumn{1}{c}{Graduates of} & \multicolumn{1}{c}{Graduates of} & \\ \addlinespace[-0.5ex] \cmidrule(lr){2-3}  \addlinespace[-0.5ex]
	tex & \shortstacking{Without \\ Covariates} & \shortstacking{With \\ Covariates} 
	tex & \shortstacking{Primary Care \\ Physicians}
	tex & Specialists
	tex & \shortstacking{Ranked MD \\ Program}
	tex & \shortstacking{Non-Ranked MD \\ Program}
	tex & Lawyers \\  \addlinespace[1ex]
	tex `tableno' \\ \addlinespace[0.5ex] \midrule 
	
	gsort effect
	
	tex \addlinespace[2ex] \multicolumn{8}{l}{\bf Panel A: Person-Level Variance Decomposition} \\ \addlinespace[1ex]
	loc level = "PL"
	forvalues k = 1(1)`=_N' {
		tex `=effect[`k']' & `=cardphysicians_`level'[`k']' & `=cardALL_`level'[`k']' & `=cardPCPDOCS_`level'[`k']' & `=cardSPECIAL_`level'[`k']' & `=cardRANKED_`level'[`k']' & `=cardNONRANKED_`level'[`k']' & `=cardlawyers_`level'[`k']' 	\\ \addlinespace[1ex]		
	} 		

	tex \addlinespace[2ex]	\multicolumn{8}{l}{\bf Panel B: CZ-Level Variance Decomposition} \\ \addlinespace[1ex]
	loc level = "CZL"
	
	forvalues k = 1(1)`=_N' {
		tex `=effect[`k']' & `=cardphysicians_`level'[`k']' & `=cardALL_`level'[`k']' & `=cardPCPDOCS_`level'[`k']' & `=cardSPECIAL_`level'[`k']' & `=cardRANKED_`level'[`k']' & `=cardNONRANKED_`level'[`k']' & `=cardlawyers_`level'[`k']' 	\\ \addlinespace[1ex]			
	} 		
	
	tex \hline \hline
	tex \end{tabular}
	tex }
	tex \end{center}
	tex \end{table}
	
	texdoc close	

*************************************************************
*** Table E.8: Correlates of Place Effects 

	* Prepare estimates
	import delimited using "${mypath}/intermediate_csv/geotwfe09-cz_correlations.csv", asdoub clear
	keep if (sample == "physicians" | (sample == "lawyers" & indepvar == "med_hhinc2016")) & indepvar != "med_hhinc2016 (physicians>10)"
	drop sort
	
	* Rename and format labels
	* Dependent variable
	replace depvar = "CZ Fixed Effect" if depvar == "Demeaned CZ-FEs"
	replace depvar = "CZ Log Income" if depvar == "Demeaned Log Earnings"
	
	* Panel A: Population Density
	replace label = "01.Log Population" if label == "Log Population"
	replace label = "02.Population Density" if label == "Population Density"
	
	* Panel B: General Economic Characteristics
	replace label = "04.Diamond and Moretti (2021) Price Index" if label == "Laspeyres Price Index"
	replace label = "05.Median Household Income in 2016 (vs.~Physician Income FE)" if indepvar == "med_hhinc2016"	
	replace label = "06.Median Household Income in 2016 (vs.~Lawyer Income FE)" if indepvar == "med_hhinc2016" & sample == "lawyers"
	replace label = "07.Rural Index, 2013" if label == "Urban->Rural Continuum Code 2013"
	replace label = "08.% College Graduates" if label == "% College Grads"
	replace label = "09.Job Growth Rate 1990-2010" if label == "Job Growth Rate 1990-2010"
	replace label = "10.Median House Value" if label == "Median House Value"
	
	* Panel C: Life Expectancy
	replace label = "12.Life Expectancy" if label == "Life Expectancy"
	replace label = "13.Finkelstein et al. (2021) Mortality Treatment Effect" if label == "FGW Mortality Trt Effect"
	
	* Panel D: Healthcare System
	replace label = "15.Total # of Physicans (2005-2017)" if label == "Total # of Physicans (All years)"
	replace label = "16.# of PCPs per 100,000" if label == "# of PCPs per 100,000"
	replace label = "17.# of Non-PCPs per 100,000" if label == "# of Non-PCPs per 100,000"
	replace label = "18.# of Medicaid Eligible per 100,000" if label == "# Medicaid Eligible per 100,000"
	replace label = "19.# of Medicare Eligible per 100,000" if label == "# Medicare Eligible per 100,000"
	replace label = "20.% Uninsured" if label == "% Uninsured"
	
	g lab_no = substr(label,1,2)
	destring lab_no, replace force
	drop if lab_no == .
	replace label = substr(label, 4, .)
	gsort lab_no -depvar
	labmask lab_no, val(label)
	encode depvar, g(depvar_no) 
	levelsof depvar, loc(depvar)
	
	keep estimate stderr min95 max95 *_no label
	reshape wide estimate stderr min95 max95, i(lab_no) j(depvar_no) 
	
	foreach var of varl *1 *2 {
		loc l = `=substr("`var'",-1,.)'
		loc f`l' : word `l' of `depvar'
		label variable `var' "`f`l''"
		tostring `var', format("%04.3fc") replace force
		replace `var' = "" if `var' == "."
		
		if (`var' != "" & strpos("`var'","stderr")) {
			replace `var' = "(" + `var' + ")"
			replace `var' = "" if `var' == "()"
		}
	}
	
	replace label = subinstr(label,"#","Number",.)
	replace label = subinstr(label,"$","\USD  ",.) if label != "Median Household Income in 2016 (CZs with \$ > \$ 10 Physicians)"
	replace label = subinstr(label,"%","Share ",.)

	* Table
	texdoc init "${tables}/geotwfe09-cz_correlations_physicians.tex", replace

	gsort lab_no
	loc tableno " "
	loc tabspec "l"	
	loc collab ""
	
	loc i = 1
	foreach v of varl estimate2 estimate1  {
		loc tabspec "`tabspec'c"
		loc tableno "`tableno' & (`i')"	
		loc collab "`collab' & `: var label `v''"
		loc ++i 
	}		

	tex \begin{table}[h!] 
	tex \caption{\bf Correlates of Place Effects \label{tab:czcharacterisitcs}} 
	tex \begin{center}
	tex \resizebox{0.95\textwidth}{!}{
	tex \begin{tabular}{`tabspec'} 
	tex \midrule \midrule \addlinespace[1ex]	
	tex `tableno' \\ 
	tex `collab' \\ \midrule \\ \addlinespace[-0.5ex]	

	foreach k of numl 1(1)`=_N' {
		
		tex `=label[`k']' & `=estimate2[`k']' & `=estimate1[`k']' \\
		tex			      & `=stderr2[`k']' & `=stderr1[`k']' \\ \addlinespace[0.5ex]	
	
	}

	tex \addlinespace[1ex] \hline \hline
	tex \end{tabular}
	tex }
	tex \end{center}
	tex \end{table}		
	
	texdoc close